<template>
  <!--统计-问题反馈单-->
  <el-container>
    <basic-crud  ref="crudRef" :option="option" v-model="formData" apiGetListUrl="/mes/problemFeedbackController/grid">
      <template #fileNames="{ row }">
        <el-button type="text" v-for="file in row.fileList" :key="file.id"  @click="downloadFileHandler(file)">{{
            `${file.showName}.${file.fileExtension};`
          }}</el-button>
      </template>
      <template #fileNames-form>
        <el-button type="text" v-for="file in formData.fileList" :key="file.id"  @click="downloadFileHandler(file)">{{
            `${file.showName}.${file.fileExtension};`
          }}</el-button>
      </template>
    </basic-crud>
  </el-container>
</template>

<script setup>
import {formatDate} from "../../../utils/formatTime"
import {ref} from "vue";
import {ElMessage} from "element-plus";
import {downloadFile} from "@/utils/file.js";
const formData=ref({})
const option = ref({
  highlightCurrentRow: true,
  addBtn: false,
  editBtn: false,
  viewBtn: true,
  delBtn: false,
  size: 'small',
  menuWidth: 80,
  column: [
    {
      label: "状态",
      prop: "status",
      width: 80,
      sortable: true,
      display:false,
      search: true,
      searchType: 'select',
      virtualize: true,
      statusShow: true,
      statusTag: true,
      statusTypeMap: {
        Created:'danger',
        Released:'success',
        Auditing:'warning'
      }
    },
    {
      label: "编号",
      prop: "code",
      overHidden: true,
      minWidth: 200,
      display:false,
    },
    {
      label: '产品型号',
      prop: 'modelName',
      search: true,
      minWidth: 180,
      display:false,
    },
    {
      label: '产品名称',
      prop: 'productName',
      search: true,
      minWidth: 180,
      display:false,
    },
    {
      label: '产品编号',
      prop: 'productCode',
      search: true,
      minWidth: 150,
      display:false,
    },
    {
      label: "创建时间",
      prop: "proposeTime",
      display:false,
      width: 120,
      formatter: (row) => {
        return row.proposeTime?.substring(0, 10) || "";
      },
    },
    {
      label: "结束时间",
      prop: "zeroingTime",
      display:false,
      width: 120,
      formatter: (row) => {
        return row.zeroingTime?.substring(0, 10) || "";
      },
    },
    {
      label: '问题类型',
      prop: 'problemClassifysText',
      width: 180,
      display:false,
      span: 24,
      formatter: (row) => {
        let text = [];
        row.problemClassifys?.map(val => {
          text.push(problemClassifysList[val]);
        });
        return  text.join('/');
      },
    },
    {
      label: "问题描述",
      prop: "problemDesc",
      display:false,
      minWidth: 260,
    },
    {
      label: "解决方案",
      prop: "solution",
      display:false,
      minWidth: 260,
    },
    {
      label: "附件",
      prop: "fileNames",
      slot: true,
      display:false,
      minWidth: 300,
    },
  ],
  group:[
    {
      label: "",
      prop: "xcinfo",
      labelWidth:100,
      column: [
        {
          label: "编号",
          prop: "code",
          gutter: 32,
          disabled: true,
          placeholder: "后台自动生成",
          span: 12,
        },
        {
          label: "单据状态",
          prop: "status",
          gutter: 32,
          type: "select",
          dicData: [
            {
              label: "未处理",
              value: "Created",
            },
            {
              label: "已处理",
              value: "Released",
            },
          ],
          value: "Created",
          span: 12,
        },
        {
          label: "型号",
          prop: "modelName",
          gutter: 32,
          disabled: true,
          span: 12,
        },
        {
          label: "产品名称",
          prop: "productName",
          disabled: true,
          gutter: 32,
          span: 12,
        },
        {
          label: "产品编号",
          prop: "productCode",
          gutter: 32,
          disabled: true,
          span: 12,
        },
        {
          label: "工序号",
          prop: "processCode",
          gutter: 32,
          disabled: true,
          span: 12,
        },
        {
          label: "工序名称",
          prop: "processName",
          gutter: 32,
          disabled: true,
          span: 12,
        },
        {
          label: "反馈人",
          prop: "proposerName",
          gutter: 32,
          disabled: true,
          span: 12,
        },

        {
          label: "创建时间",
          prop: "proposeTime",
          type: "datetime",
          value: formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"),
          gutter: 32,
          formatter: (row) => {
            return formatDate(row.proposeTime, "yyyy-MM-dd HH:mm:ss");
          },
        },
        {
          label: "结束时间",
          prop: "zeroingTime",
          type: "datetime",
          gutter: 32,
          formatter: (row) => {
            return formatDate(row.zeroingTime, "yyyy-MM-dd HH:mm:ss");
          },
        },
        {
          label:'问题类型',
          prop:'problemClassifys',
          type:'checkbox',
          border: true,
          dicData: [{
            label:'人力问题',
            value:'manpowerConflict'
          },{
            label:'设备资源冲突',
            value:'deviceConflict'
          },{
            label:'设备故障',
            value:'deviceBreakdown'
          },{
            label:'物料未齐备',
            value:'supportUnComplete'
          },{
            label:'物料故障',
            value:'materialProblem'
          },{
            label:'设计文件问题',
            value:'designFileProblem'
          },{
            label:'工艺文件问题',
            value:'processFileProblem'
          },{
            label:'软件问题',
            value:'softwareProblem'
          },{
            label:'生产环境问题',
            value:'envProblem'
          },{
            label:'环境试验资源冲突',
            value:'envTestClash'
          },{
            label:'其他问题',
            value:'otherProblem'
          }],
          span:24
        },
        {
          label:'责任人',
          prop:'dutyUserName',
          span: 12,
        }, {
          label: '责任部门',
          prop: 'dutyDeptName',
          span: 12,
        },
        {
          label: "问题描述",
          prop: "problemDesc",
          type: "textarea",
          gutter: 32,
          minRows: 3,
          maxRows: 5,
          span: 24,
        },
        {
          label: "解决方案",
          prop: "solution",
          type: "textarea",
          gutter: 32,
          minRows: 3,
          maxRows: 5,
          span: 24,
        },
        {
          label: "附件",
          prop: "fileNames",
          minWidth: 300,
          editDisplay:false,
          addDisplay:false,
          formslot:true,
          viewDisplay:true,
          span:24
        }
      ],
    },
  ]
})

const problemClassifysList={
  "manpowerConflict": "人力问题",
  "deviceConflict": "设备资源冲突",
  "deviceBreakdown": "设备故障",
  "supportUnComplete": "物料未齐备",
  "materialProblem":'物料故障',
  'designFileProblem':'设计文件问题',
  'processFileProblem':'工艺文件问题',
  'softwareProblem':'软件问题',
  'envProblem':'生产环境问题',
  'envTestClash':'环境试验资源冲突',
  'otherProblem':'其他问题',
}

//文件下载
const downloadFileHandler=async (row)=> {
  downloadFile(row.id, row.name, "/mes");
}
</script>

<style scoped>

</style>
